/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

// Created on 31.10.2003 by RST.
// $Id: pmove_state_t.java,v 1.3 2005/01/21 01:08:48 cawe Exp $
using System;
using Com = Suake2.UI.qcommon.Com;
using Math3D = Suake2.UI.util.Math3D;
//UPGRADE_TODO: The type 'java.nio.ByteBuffer' could not be found. If it was not included in the conversion, there may be compiler issues. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1262'"
using ByteBuffer = java.nio.ByteBuffer;
namespace Suake2.UI.game
{
	
	public class pmove_state_t
	{
		//	this structure needs to be communicated bit-accurate
		//	from the server to the client to guarantee that
		//	prediction stays in sync, so no floats are used.
		//	if any part of the game code modifies this struct, it
		//	will result in a prediction error of some degree.
		
		public int pm_type;
		
		public short[] origin = new short[]{0, 0, 0}; // 12.3
		public short[] velocity = new short[]{0, 0, 0}; // 12.3
		/// <summary>ducked, jump_held, etc. </summary>
		public sbyte pm_flags;
		/// <summary>each unit = 8 ms. </summary>
		public sbyte pm_time;
		public short gravity;
		/// <summary>add to command angles to get view direction. </summary>
		public short[] delta_angles = new short[]{0, 0, 0};
		/// <summary>changed by spawns, rotating objects, and teleporters.</summary>
		
		private static pmove_state_t prototype = new pmove_state_t();
		
		public virtual void  clear()
		{
			this.set_Renamed(prototype);
		}
		
		public virtual void  set_Renamed(pmove_state_t from)
		{
			pm_type = from.pm_type;
			Math3D.VectorCopy(from.origin, origin);
			Math3D.VectorCopy(from.velocity, velocity);
			pm_flags = from.pm_flags;
			pm_time = from.pm_time;
			gravity = from.gravity;
			Math3D.VectorCopy(from.delta_angles, delta_angles);
		}
		
		public bool equals(pmove_state_t p2)
		{
			if (pm_type == p2.pm_type && origin[0] == p2.origin[0] && origin[1] == p2.origin[1] && origin[2] == p2.origin[2] && velocity[0] == p2.velocity[0] && velocity[1] == p2.velocity[1] && velocity[2] == p2.origin[2] && pm_flags == p2.pm_flags && pm_time == p2.pm_time && gravity == gravity && delta_angles[0] == p2.delta_angles[0] && delta_angles[1] == p2.delta_angles[1] && delta_angles[2] == p2.origin[2])
				return true;
			
			return false;
		}
		
		/// <summary>Reads the playermove from the file.</summary>
		//UPGRADE_TODO: Class 'java.io.RandomAccessFile' was converted to 'System.IO.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioRandomAccessFile'"
		public virtual void  load(System.IO.FileStream f)
		{
			
			System.IO.BinaryReader temp_BinaryReader;
			temp_BinaryReader = new System.IO.BinaryReader(f);
			temp_BinaryReader.BaseStream.Position = f.Position;
			pm_type = temp_BinaryReader.ReadInt32();
			
			System.IO.BinaryReader temp_BinaryReader2;
			temp_BinaryReader2 = new System.IO.BinaryReader(f);
			temp_BinaryReader2.BaseStream.Position = f.Position;
			origin[0] = temp_BinaryReader2.ReadInt16();
			System.IO.BinaryReader temp_BinaryReader3;
			temp_BinaryReader3 = new System.IO.BinaryReader(f);
			temp_BinaryReader3.BaseStream.Position = f.Position;
			origin[1] = temp_BinaryReader3.ReadInt16();
			System.IO.BinaryReader temp_BinaryReader4;
			temp_BinaryReader4 = new System.IO.BinaryReader(f);
			temp_BinaryReader4.BaseStream.Position = f.Position;
			origin[2] = temp_BinaryReader4.ReadInt16();
			
			System.IO.BinaryReader temp_BinaryReader5;
			temp_BinaryReader5 = new System.IO.BinaryReader(f);
			temp_BinaryReader5.BaseStream.Position = f.Position;
			velocity[0] = temp_BinaryReader5.ReadInt16();
			System.IO.BinaryReader temp_BinaryReader6;
			temp_BinaryReader6 = new System.IO.BinaryReader(f);
			temp_BinaryReader6.BaseStream.Position = f.Position;
			velocity[1] = temp_BinaryReader6.ReadInt16();
			System.IO.BinaryReader temp_BinaryReader7;
			temp_BinaryReader7 = new System.IO.BinaryReader(f);
			temp_BinaryReader7.BaseStream.Position = f.Position;
			velocity[2] = temp_BinaryReader7.ReadInt16();
			
			pm_flags = (sbyte) f.ReadByte();
			pm_time = (sbyte) f.ReadByte();
			System.IO.BinaryReader temp_BinaryReader8;
			temp_BinaryReader8 = new System.IO.BinaryReader(f);
			temp_BinaryReader8.BaseStream.Position = f.Position;
			gravity = temp_BinaryReader8.ReadInt16();
			
			System.IO.BinaryReader temp_BinaryReader9;
			temp_BinaryReader9 = new System.IO.BinaryReader(f);
			temp_BinaryReader9.BaseStream.Position = f.Position;
			temp_BinaryReader9.ReadInt16();
			
			System.IO.BinaryReader temp_BinaryReader10;
			temp_BinaryReader10 = new System.IO.BinaryReader(f);
			temp_BinaryReader10.BaseStream.Position = f.Position;
			delta_angles[0] = temp_BinaryReader10.ReadInt16();
			System.IO.BinaryReader temp_BinaryReader11;
			temp_BinaryReader11 = new System.IO.BinaryReader(f);
			temp_BinaryReader11.BaseStream.Position = f.Position;
			delta_angles[1] = temp_BinaryReader11.ReadInt16();
			System.IO.BinaryReader temp_BinaryReader12;
			temp_BinaryReader12 = new System.IO.BinaryReader(f);
			temp_BinaryReader12.BaseStream.Position = f.Position;
			delta_angles[2] = temp_BinaryReader12.ReadInt16();
		}
		
		/// <summary>Writes the playermove to the file. </summary>
		//UPGRADE_TODO: Class 'java.io.RandomAccessFile' was converted to 'System.IO.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioRandomAccessFile'"
		public virtual void  write(System.IO.FileStream f)
		{
			
			System.IO.BinaryWriter temp_BinaryWriter;
			temp_BinaryWriter = new System.IO.BinaryWriter(f);
			temp_BinaryWriter.Write((System.Int32) pm_type);
			
			System.IO.BinaryWriter temp_BinaryWriter2;
			temp_BinaryWriter2 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter2.Write((System.Int16) origin[0]);
			System.IO.BinaryWriter temp_BinaryWriter3;
			temp_BinaryWriter3 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter3.Write((System.Int16) origin[1]);
			System.IO.BinaryWriter temp_BinaryWriter4;
			temp_BinaryWriter4 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter4.Write((System.Int16) origin[2]);
			
			System.IO.BinaryWriter temp_BinaryWriter5;
			temp_BinaryWriter5 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter5.Write((System.Int16) velocity[0]);
			System.IO.BinaryWriter temp_BinaryWriter6;
			temp_BinaryWriter6 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter6.Write((System.Int16) velocity[1]);
			System.IO.BinaryWriter temp_BinaryWriter7;
			temp_BinaryWriter7 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter7.Write((System.Int16) velocity[2]);
			
			f.WriteByte((byte) pm_flags);
			f.WriteByte((byte) pm_time);
			System.IO.BinaryWriter temp_BinaryWriter8;
			temp_BinaryWriter8 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter8.Write((System.Int16) gravity);
			
			System.IO.BinaryWriter temp_BinaryWriter9;
			temp_BinaryWriter9 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter9.Write((System.Int16) 0);
			
			System.IO.BinaryWriter temp_BinaryWriter10;
			temp_BinaryWriter10 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter10.Write((System.Int16) delta_angles[0]);
			System.IO.BinaryWriter temp_BinaryWriter11;
			temp_BinaryWriter11 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter11.Write((System.Int16) delta_angles[1]);
			System.IO.BinaryWriter temp_BinaryWriter12;
			temp_BinaryWriter12 = new System.IO.BinaryWriter(f);
			temp_BinaryWriter12.Write((System.Int16) delta_angles[2]);
		}
		
		public virtual void  dump()
		{
			Com.Println("pm_type: " + pm_type);
			
			Com.Println("origin[0]: " + origin[0]);
			Com.Println("origin[1]: " + origin[0]);
			Com.Println("origin[2]: " + origin[0]);
			
			Com.Println("velocity[0]: " + velocity[0]);
			Com.Println("velocity[1]: " + velocity[1]);
			Com.Println("velocity[2]: " + velocity[2]);
			
			Com.Println("pmflags: " + pm_flags);
			Com.Println("pmtime: " + pm_time);
			Com.Println("gravity: " + gravity);
			
			Com.Println("delta-angle[0]: " + delta_angles[0]);
			Com.Println("delta-angle[1]: " + delta_angles[0]);
			Com.Println("delta-angle[2]: " + delta_angles[0]);
		}
	}
}